//       John Broome           //
//                             //
//     Cs 331 Project 1        //
//                             //
//        Bubble Sort          //
//                             //
//   Sorts in ascending order  //
/////////////////////////////////

// Original code found in "Data Abstraction & Problem Soving with Java"
// 2005., Carrano, F., Prichard, J.; pg. 482

public class BubbleSort {
    public static void bubbleSort(int[] theArray, int n) {
        
        boolean sorted = false;
        
        for(int i = 1; (i < n) && !sorted; ++i){
            //sorted = true;
            for(int j = 0; j < n-i; j++){
                
                int nextNum = j+1;
                
                if(theArray[j] > theArray[nextNum]) {
                    
                    //exchanging the items in the array
                    int temp = theArray[j];
                    theArray[j] = theArray[nextNum];
                    theArray[nextNum] = temp;
                    sorted = false;
                    
                }//end if
                
            }//end for loop
            
        }//end 1st for loop
        
        
    }//end bubblesort
    
}


